package com.ruoyi.kenuo.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.kenuo.mapper.KernelApplyMapper;
import com.ruoyi.kenuo.mapper.KernelMeasureRecordMapper;
import com.ruoyi.kenuo.mapper.KernelMyPatientMapper;
import com.ruoyi.kenuo.mapper.MessagesMapper;
import com.ruoyi.kenuo.service.IMyUserService;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserPostMapper;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author POLO_TANG
 * @version 1.0.0
 * @ClassName IMyUserServiceImpl
 * @description: TODO
 * @date 2023年09月15日
 */
@Service
public class IMyUserServiceImpl implements IMyUserService {


    @Autowired
    private SysUserRoleMapper userRoleMapper;

    @Autowired
    private SysUserPostMapper userPostMapper;

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private MessagesMapper messagesMapper;
    @Autowired
    private KernelMeasureRecordMapper recordMapper;
    @Autowired
    private KernelMyPatientMapper patientMapper;

    @Autowired
    private KernelApplyMapper kernelApplyMapper;

    @Override
    public AjaxResult offUser(SysUser user) {
        Long[] userIds = new Long[1];
        userIds[0] = user.getUserId();
        //根据账号删除和我相关的消息
        messagesMapper.deleteByUserName(user.getUserName());
        //清除个人测量记录
        recordMapper.deleteByUserName(user.getUserName());
        //删除我的医生或我的患者
        patientMapper.deleteByUserName(user.getUserName());
        //删除申请 关系
        kernelApplyMapper.deleteByUserName(user.getUserName());
        // 删除用户与角色关联
        userRoleMapper.deleteUserRole(userIds);
        // 删除用户与岗位关联
        userPostMapper.deleteUserPost(userIds);
        //删除用户
        userMapper.deleteUserByIds(userIds);
        return AjaxResult.success();
    }
}
